package com.hspedu.collection_;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * @author 谷其昊
 * @version 1.0
 * @date 2022/2/6
 * @time 17:21
 */
public class CollectionExercise {
    public static void main(String[] args) {
        Dog jack = new Dog("jack", 1);
        Dog bob = new Dog("bob", 2);
        Dog lucy = new Dog("lucy", 3);

        List list = new ArrayList();
        list.add(jack);
        list.add(bob);
        list.add(lucy);

        Iterator iterator = list.iterator();
        while (iterator.hasNext()){
            Object dog = iterator.next();
            System.out.println(dog);
        }
        System.out.println("=================");
        for (Object dog : list) {
            System.out.println(dog);
        }
    }
}

class Dog{
    private String name;
    private int age;

    @Override
    public String toString() {
        return "Dog{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    public Dog(String name, int age) {
        this.name = name;
        this.age = age;
    }
}
